<template>
  <div class="detail-wrapper">
    <el-page-header @back="goBack" content="供应商详情"> </el-page-header>
    <!-- <el-divider></el-divider> -->
    <div class="topBox paddingBorder">
      <el-descriptions
        :title="dataForm.name"
        :column="3"
        :labelStyle="labelStyle"
        :contentStyle="contentStyle"
        border
      >
        <template slot="extra">
          <el-button type="primary" size="small" @click="toEdit"
            >编辑</el-button
          >
          <el-button type="primary" size="small" @click="handleDelete"
            >删除</el-button
          >
        </template>
        <el-descriptions-item>
          <template slot="label"> 创建人 </template>
          {{ dataForm.add_user_name }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 创建时间 </template>
          {{ dataForm.add_time }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 最后修改人 </template>
          {{ dataForm.operator_user }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 修改时间 </template>
          {{ dataForm.operator_time }}
        </el-descriptions-item>
      </el-descriptions>
    </div>

    <div class="top36 prodBox paddingBorder">
      <div class="titleLabel">供应商信息</div>
      <el-descriptions
        class="top36"
        title="基本信息"
        :column="3"
        :labelStyle="labelStyle"
        :contentStyle="contentStyle"
        border
      >
        <el-descriptions-item>
          <template slot="label"> 供应商编号 </template>
          {{ dataForm.supplier_serial }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 供应商名称 </template>
          {{ dataForm.name }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 法人代表 </template>
          {{ dataForm.legal_person }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 联系人 </template>
          {{ dataForm.username }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 联系电话 </template>
          {{ dataForm.phone }}
        </el-descriptions-item>
      </el-descriptions>

      <el-descriptions
        class="top36"
        title="财务信息"
        :column="3"
        :labelStyle="labelStyle"
        :contentStyle="contentStyle"
        border
      >
        <el-descriptions-item>
          <template slot="label"> 开户银行 </template>
          {{ dataForm.bank_deposit }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 银行账户 </template>
          {{ dataForm.bank_account }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 纳税人识别号 </template>
          {{ dataForm.duty_paragraph }}
        </el-descriptions-item>
      </el-descriptions>

      <!-- <el-descriptions class="top36" title="财务信息" border>
        
      </el-descriptions> -->
      <div class="descMockBox">
        <div class="descMockLabel">供应商物料</div>
        <el-table
          :data="dataForm.material_list"
          border
          style="width: 100%; margin-top: 20px"
        >
          <el-table-column
            type="index"
            label="序号"
            header-align="center"
            align="center"
            width="80"
          ></el-table-column>
          <el-table-column
            prop="material_serial"
            label="物料编号"
            header-align="center"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="name"
            label="物料"
            header-align="center"
            align="center"
          >
            <template slot-scope="scope">
              <div class="disCenter materialBox">
                <div class="imgBox">
                  <img :src="scope.row.master_pic" />
                </div>
                <div class="rightBox">{{ scope.row.name }}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="specifications_model"
            label="规格型号"
            header-align="center"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="material_type_str"
            label="物料类别"
            header-align="center"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="material_attr_str"
            label="物料属性"
            header-align="center"
            align="center"
          >
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { addDynamicRoute } from '@/router'
import { getSupplierBomDetail, deleteSupplier } from '@/api'
export default {
  data() {
    return {
      visible: false,
      roleList: [],
      roleIdListDefault: [],
      dataForm: {
        name: '',
        versions: '',
      },
      labelStyle: {
        width: '150px',
      },
      contentStyle: {
        width: '28vw',
      },
    }
  },
  computed: {},
  activated() {
    const id = this.$route.params.id
    this.dataForm.id = id
    if (id) this.fetchDetail(id)
  },
  methods: {
    async handleDelete() {
      const id = this.dataForm.id
      this.$confirm('此操作将删除该供应商数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          const res = await deleteSupplier({ id })
          if (res?.status === 1) {
            this.$message.success(res?.msg || '')
            this.$router.go(-1)
          }
        })
        .catch(() => {})
    },
    async fetchDetail(id) {
      const params = {
        id,
      }
      const res = await getSupplierBomDetail(params)
      console.log(res)
      if (res?.status === 1) {
        const data = res?.data || {}
        this.dataForm = data
        console.log(data)
      }
    },
    goBack() {
      this.$router.go(-1)
    },
    toEdit() {
      const routeParams = {
        routeName: `supply-management__add`,
        title: `供应商管理 - 编辑`,
        path: 'supply/management-add',
        params: {
          id: this.dataForm.id || '',
        },
      }
      addDynamicRoute(routeParams, this.$router)
    },
  },
}
</script>

<style lang="scss" scoped>
.detail-wrapper {
  background: #fff;
  padding: 20px;
  ::v-deep .el-page-header__title,
  .el-page-header__content {
    font-size: 12px;
  }

  ::v-deep .el-page-header__content {
    font-size: 12px;
  }

  .topBox {
    margin-top: 36px;
    ::v-deep .el-descriptions__title {
      font-size: 20px;
      font-weight: 600;
      position: relative;
      padding-left: 16px;
      color: #303133;
      &::before {
        background: $mainColor;
        content: '';
        display: inline-block;
        height: 20px;
        left: 0;
        position: absolute;
        top: calc(50% - 10px);
        width: 3px;
      }
    }
  }

  .prodBox {
    .prodImgBox {
      .imgItem {
        width: 64px;
        height: 64px;
        margin-left: 12px;
        cursor: pointer;
        &:first-child {
          margin-left: 0;
        }
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }

  .materialBox {
    padding-left: 6px;
    .imgBox {
      width: 64px;
      height: 64px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .rightBox {
      margin-left: 14px;
      text-align: left;
      .top {
        max-width: 200px;
        margin-bottom: 6px;
      }
      .bottom {
        color: $mainColor;
      }
    }
  }
}
</style>

<style lang="scss">
::v-deep .el-page-header__title {
  font-size: 12px;
}
</style>
